<template>
<div> 
   <!--  -->
   <el-tree  :load="loadNode" :props="props"  lazy  show-checkbox @node-click="clickTree"></el-tree>
</div>
</template>
<script>
import api from '@/api/index'
export default {
  name: "GoodsTree",
  data() {
      return {
        props: {
          label: 'name',
        },
      };
    },
  created(){

  },   
  methods: {
      clickTree(data, node) {
        this.$emit('changeTree',data)
      },
      async loadNode(node, resolve) {
        if (node.level === 0) {
          let res = await this.$api.getGoodsItemCategory()
          if(res.data.status ===200){
             return resolve(res.data.data.result);
          }else{
              return resolve([])
          }
        }
        if (node.level > 1){
              return resolve([]);
        }
        setTimeout(() => {
          const data = [
            { name: '苹果'},
            { name: '香蕉'}
          ];
          resolve(data);
        }, 500);
      },
    },

}
</script>


<style lang="less"  scoped>



</style>